package autokeyboard.handler;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JLabel;
import javax.swing.Timer;

public class AboutWindowEvent
{
	private Timer			timer;

	private JLabel			lblAuthor_Name;
	private JLabel			lblAuthor_Job;
	private JLabel			lblAuthor_Email;

	private String			stAuthor_Name	= "Name: Huỳnh Quang Thái";
	private String			stAuthor_Job	= "Job: Student of IT at NL University";
	private String			stAuthor_Email	= "E-mail: holdthehand@gmail.com";

	

	public AboutWindowEvent(JLabel lblAuthor_Name, JLabel lblAuthor_Job, JLabel lblAuthor_Email)
	{
		this.lblAuthor_Name = lblAuthor_Name;
		this.lblAuthor_Job = lblAuthor_Job;
		this.lblAuthor_Email = lblAuthor_Email;
		timer = new Timer(50, action);
	}

	private int counter = 0;
	private ActionListener	action			= new ActionListener()
											{

												@Override
												public void actionPerformed(ActionEvent e)
												{
													if(counter <stAuthor_Name.length())
													{
														lblAuthor_Name.setText(lblAuthor_Name.getText() + stAuthor_Name.charAt(counter));
														counter++;
													}
													else if(counter == stAuthor_Name.length())
													{
														timer.stop();
														counter = 0;
														timer = new Timer(50, action1);
														timer.start();
													}
												}
											};
	private ActionListener	action1			= new ActionListener()
											{

												@Override
												public void actionPerformed(ActionEvent e)
												{
													if(counter <stAuthor_Job.length())
													{
														lblAuthor_Job.setText(lblAuthor_Job.getText() + stAuthor_Job.charAt(counter));
														counter++;
													}
													else if(counter == stAuthor_Job.length())
													{
														timer.stop();
														counter = 0;
														timer = new Timer(50, action2);
														timer.start();
													}
												}
											};
											
	private ActionListener	action2			= new ActionListener()
											{

												@Override
												public void actionPerformed(ActionEvent e)
												{
													if(counter <stAuthor_Email.length())
													{
														lblAuthor_Email.setText(lblAuthor_Email.getText() + stAuthor_Email.charAt(counter));
														counter++;
													}
													else if(counter >= stAuthor_Email.length()  && counter < stAuthor_Email.length() + 50)
														counter++;
													else if(counter == stAuthor_Email.length() + 50)
													{
														lblAuthor_Name.setText("");
														lblAuthor_Job.setText("");
														lblAuthor_Email.setText("");
														counter = 0;
														timer.stop();
														timer = new Timer(50, action);
														timer.start();
													}
												}
											};
	public void start()
	{
		timer.start();
	}

	public void stop()
	{
		timer.stop();
	}

}
